<template>
  <div class="app-container">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>管道维护费设置</span>
      </div>
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
        <el-row :gutter="10" class="mb8">
          <el-col :span="24">
            <el-form-item label="收费类型" prop="status">
              <el-radio v-model="form.wlwPrice" label="1">统一收费</el-radio>
              <el-radio v-model="form.wlwPrice" label="2">工程工料费用百分比</el-radio>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="客户类型" prop="status">
              <el-select v-model="queryParams.status" placeholder="客户类型" clearable>
                <el-option v-for="dict in dict.type.sys_normal_disable" :key="dict.value" :label="dict.label"
                  :value="dict.value" />
              </el-select>
            </el-form-item>
            <el-form-item label="收费金额" prop="postCode">
              <el-input v-model="queryParams.postCode" placeholder="请输入收费金额" clearable @keyup.enter.native="handleQuery"
                type="number">
                <template slot="append">元</template>
              </el-input>
            </el-form-item>
            <el-form-item label="工程工料费用百分比" prop="postCode" label-width="140px">
              <el-input v-model="queryParams.postCode" placeholder="工程工料费用百分比" clearable @keyup.enter.native="handleQuery"
                type="number">
                <template slot="append">%</template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="收费时段" prop="status">
              <el-select v-model="queryParams.status" placeholder="收费时段" clearable>
                <el-option v-for="dict in dict.type.sys_normal_disable" :key="dict.value" :label="dict.label"
                  :value="dict.value" />
              </el-select>
            </el-form-item>
            <el-form-item label="优惠时段" prop="status">
              <el-select v-model="queryParams.status" placeholder="优惠时段(月)" clearable>
                <el-option v-for="dict in dict.type.sys_normal_disable" :key="dict.value" :label="dict.label"
                  :value="dict.value" />
              </el-select>
            </el-form-item>
            <el-form-item label="开始收取时间" prop="status" label-width="100px">
              <el-date-picker v-model="queryParams.status" type="date" placeholder="开始收取时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
            v-hasPermi="['systemSetup:maintenanceFee:remove']">删除</el-button>
          <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
            v-hasPermi="['systemSetup:maintenanceFee:add']">新增</el-button>
        </el-form-item>
      </el-form>
      <el-row :gutter="10" class="mb8">
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>
      <el-table v-loading="loading" :data="pipelinefeeList" border @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="客户类型" align="center" prop="postId" />
        <el-table-column label="收费时段" align="center" prop="postCode" />
        <el-table-column label="收费金额" align="center" prop="postName" />
        <el-table-column label="优惠时段" align="center" prop="postSort" />
        <el-table-column label="百分比" align="center" prop="postSort" />
        <el-table-column label="收费类别" align="center" prop="postSort" />
        <el-table-column label="开始收取日期" align="center" prop="postSort" />
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
              v-hasPermi="['systemSetup:maintenanceFee:edit']">修改</el-button>
            <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
              v-hasPermi="['systemSetup:maintenanceFee:remove']">删除</el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
        @pagination="getList" />
    </el-card>
    <el-card class="box-card" style="margin-top: 20px">
      <div slot="header" class="clearfix">
        <span>预交维护费设置</span>
      </div>
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item label="预交月数" prop="postCode">
          <el-input v-model="queryParams.postCode" placeholder="请输入预交月数" clearable @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="实收月数" prop="postCode">
          <el-input v-model="queryParams.postCode" placeholder="请输入实收月数" clearable @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd2"
            v-hasPermi="['systemSetup:maintenanceFee:add']">新增</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete2"
            v-hasPermi="['systemSetup:maintenanceFee:remove']">删除</el-button>
        </el-col>
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>
      <el-table v-loading="loading" :data="pipelinefeeList" border @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="预交费月数" align="center" prop="postId" />
        <el-table-column label="实收月数" align="center" prop="postCode" />
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate2(scope.row)"
              v-hasPermi="['systemSetup:maintenanceFee:edit']">修改</el-button>
            <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete2(scope.row)"
              v-hasPermi="['systemSetup:maintenanceFee:remove']">删除</el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
        @pagination="getList" />
    </el-card>

    <!-- 管理维护费添加或修改岗位对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row :gutter="10" class="mb8">
          <el-col :span="12">
            <el-form-item label="客户类型" prop="userType">
              <el-select v-model="form.userType" placeholder="客户类型" clearable>
                <el-option :key="1" :label="1" :value="1" />
                <el-option :key="2" :label="2" :value="2" />
                <el-option :key="3" :label="3" :value="3" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="收费时段" prop="chargePeriod">
              <el-select v-model="form.chargePeriod" placeholder="收费时段" clearable>
                <el-option :key="1" :label="1" :value="1" />
                <el-option :key="2" :label="2" :value="2" />
                <el-option :key="3" :label="3" :value="3" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="收费金额" prop="feeAmount">
              <el-input v-model="form.feeAmount" placeholder="请输入收费金额" type="number" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="优惠时段" prop="discountPeriod">
              <el-select v-model="form.discountPeriod" placeholder="优惠时段" clearable>
                <el-option :key="1" :label="1" :value="1" />
                <el-option :key="2" :label="2" :value="2" />
                <el-option :key="3" :label="3" :value="3" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="百分比" prop="projectFeePercent">
              <el-input v-model="form.projectFeePercent" placeholder="请输入百分比" type="number">
                <template slot="append">%</template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="收费类别" prop="chargeType">
              <el-select v-model="form.chargeType" placeholder="收费类别" clearable>
                <el-option key="1" label="统一收费" value="1" />
                <el-option key="2" label="工程工料费用百分比" value="2" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="开始收取日期" prop="startTime" label-width="120px">
              <el-date-picker v-model="form.startTime" type="date" placeholder="选择日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 预交维护费添加或修改岗位对话框 -->
    <el-dialog :title="title" :visible.sync="open2" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row :gutter="10" class="mb8">
          <el-col :span="24">
            <el-form-item label="预交月数" prop="postCode">
              <el-input v-model="form.postCode" placeholder="请输入预交月数" type="number" />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="实收月数" prop="postCode">
              <el-input v-model="form.postCode" placeholder="请输入实收月数" type="number" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm2">确 定</el-button>
        <el-button @click="cancel2">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listPipelinefee,
  getPipelinefee,
  addPipelinefee,
  updatePipelinefee,
  delPipelinefee,
  listPrepayfee,
  getPrepayfee,
  addPrepayfee,
  updatePrepayfee,
  delPrepayfee,
} from "@/api/systemSetup/maintenanceFee";

export default {
  name: "maintenanceFee",
  dicts: ["sys_normal_disable"],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 管道维护费设置选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 管道维护费设置总条数
      total: 0,
      // 管道维护费设置表格数据
      pipelinefeeList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      open2: false,
      // 管道维护费设置查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        postCode: undefined,
        postName: undefined,
        status: undefined,
      },
      // 管道维护费设置表单参数
      form: {},
      // 管道维护费设置表单校验
      rules: {
        userType: [
          { required: true, message: "客户类型不能为空", trigger: "change" },
        ],
        chargePeriod: [
          { required: true, message: "收费时段不能为空", trigger: "change" },
        ],
        feeAmount: [
          { required: true, message: "收费金额不能为空", trigger: "blur" },
        ],
        discountPeriod: [
          { required: true, message: "优惠时段不能为空", trigger: "change" },
        ],
        projectFeePercent: [
          { required: true, message: "百分比不能为空", trigger: "blur" },
        ],
        chargeType: [
          { required: true, message: "收费类别不能为空", trigger: "change" },
        ],
        startTime: [
          { required: true, message: "开始收取日期不能为空", trigger: "change" },
        ],
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询岗位列表 */
    getList() {
      this.loading = true;
      listPipelinefee(this.queryParams).then((response) => {
        this.pipelinefeeList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    cancel2() {
      this.open2 = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        postId: undefined,
        postCode: undefined,
        postName: undefined,
        postSort: 0,
        status: "0",
        remark: undefined,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.postId);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "管理维护费-新增";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const postId = row.postId || this.ids;
      getPost(postId).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "管理维护费-修改";
      });
    },
    /** 新增按钮操作 */
    handleAdd2() {
      this.reset();
      this.open2 = true;
      this.title = "预交维护费-新增";
    },
    /** 修改按钮操作 */
    handleUpdate2(row) {
      this.reset();
      const postId = row.postId || this.ids;
      getPipelinefee(postId).then((response) => {
        this.form = response.data;
        this.open2 = true;
        this.title = "预交维护费-修改";
      });
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.postId != undefined) {
            updatePipelinefee(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPipelinefee(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    submitForm2: function () {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.postId != undefined) {
            updatePost(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPost(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const postIds = row.postId || this.ids;
      this.$modal
        .confirm('是否确认删除岗位编号为"' + postIds + '"的数据项？')
        .then(function () {
          return delPipelinefee(postIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => { });
    },
    /** 删除按钮操作 */
    handleDelete2(row) {
      const postIds = row.postId || this.ids;
      this.$modal
        .confirm('是否确认删除岗位编号为"' + postIds + '"的数据项？')
        .then(function () {
          return delPost(postIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => { });
    },
  },
};
</script>
